﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace nzy3d_wpfDemo
{
    class MyMapper : nzy3D.Plot3D.Builder.Mapper
    {
        public double[][] rawData { get; set; }

        public override double f(double x, double y)
        {
            return rawData[(int)x][(int)y];// 10 * Math.Sin(x / 10) * Math.Cos(y / 20) * x;
        }

         
        public MyMapper(string filepath)
        {
            //OpenResultCSVFile(@"E:\Test\WangWanJiangChaZhi\QuMianChaZhi\result2.csv");
            //OpenResultCSVFile(@"E:\ProjectOut\王万江\TestSolution\kriging_test\output.csv");
            OpenResultCSVFile(filepath);
        }



        public void OpenResultCSVFile(string filePath)
        {
            rawData = new double[80][];
           

            Encoding encoding = Encoding.ASCII;//

            FileStream fs = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            //StreamReader sr = new StreamReader(fs, Encoding.UTF8);
            StreamReader sr = new StreamReader(fs, encoding);
            //string fileContent = sr.ReadToEnd();
            //encoding = sr.CurrentEncoding;
            //记录每次读取的一行记录
            string strLine = "";
            //记录每行记录中的各字段内容
            string[] aryLine = null;
            string[] tableHead = null;
            //标示列数
            int columnCount = 0;
            //标示是否是读取的第一行
            bool IsFirst = true;
            //逐行读取CSV中的数据


            double max = -100000;
            double min = 100000;

            Dictionary<string, int> elementCount = new Dictionary<string, int>();

            SortedDictionary<int, int> ValueCount = new SortedDictionary<int, int>();

            int xIndex = 0;
            while ((strLine = sr.ReadLine()) != null)
            {
                aryLine = strLine.Split(',');

                rawData[xIndex] = new double[80];

                for (int yIndex = 0; yIndex < 80; yIndex++)
                {
                    if(String.IsNullOrEmpty(aryLine[yIndex]))
                    {
                        break;
                    }
                    double zValueIn = double.Parse(aryLine[yIndex]);

                    rawData[xIndex][yIndex] = zValueIn;
                }

                xIndex++;

            }
            sr.Close();
            fs.Close();
        }


    }
}
